/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.crm.workorder.service.impl.TaskGroupServiceImpl
   Module Description   :

   Date Created      : 2011/3/22
   Original Author   : cut7man
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.crm.workorder.service.impl;

import javax.annotation.Resource;

import org.springframework.transaction.annotation.Transactional;

import com.yaodian100.core.common.service.BaseManager;
import com.yaodian100.crm.workorder.entity.TaskGroupUser;
import com.yaodian100.crm.workorder.service.TaskGroupService;

/**
 * @author cut7man
 * 
 */
public class TaskGroupServiceImpl implements TaskGroupService {
	@Resource
	private BaseManager baseMgr;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.yaodian100.crm.workorder.service.TaskGroupService#setDefaultGroup(java.lang.String, java.lang.String)
	 */
	@Override
	@Transactional(readOnly = false)
	public void setDefaultGroup(String username, String groupUserId) {
		Object[] tgus = baseMgr.queryByHql("from TaskGroupUser where user.username=?", new Object[] { username });
		for (Object obj : tgus) {
			TaskGroupUser tgu = (TaskGroupUser) obj;
			tgu.setDefaultGroup(false);
			baseMgr.update(tgu);
		}
		TaskGroupUser tgu = (TaskGroupUser) baseMgr.get(TaskGroupUser.class, Long.valueOf(groupUserId));

		tgu.setDefaultGroup(true);
		baseMgr.update(tgu);
	}

}
